package com.iflytek.controller;

import com.iflytek.common.Result;
import com.iflytek.dto.CollectDTO;
import com.iflytek.dto.PageDTO;
import com.iflytek.service.CollectService;
import com.iflytek.vo.CollectVO;
import com.iflytek.vo.PageVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * @author h_t
 * @since 2023-09-23
 */
@RestController
@RequestMapping("/api/collect")
public class CollectController{
    @Resource
    public CollectService collectService;

    /**
     * 查询所有收藏（非分页）findAll
     * @return
     */
    @ApiOperation("查询全部")
    @GetMapping("")
    Result<List<CollectVO>> findAll() {
        return collectService.findAll();
    }

    /**
     * 保存收藏save
     * @param dto
     * @return
     */
    @ApiOperation("保存")
    @PostMapping("")
    Result<Boolean> saveCollect(@RequestBody CollectDTO dto) {
        return collectService.saveCollect(dto);
    }

    /**
     * 更新收藏信息update
     * @param dto
     * @return
     */
    @ApiOperation("更新")
    @PutMapping("")
    Result<Boolean> updateCollect(@RequestBody CollectDTO dto) {
        return collectService.updateCollect(dto);
    }

    /**
     * 收藏分页查询findPage
     * @param dto
     * @return
     */
    @ApiOperation("分页")
    @GetMapping("/page/front")
    Result<PageVO<CollectVO>> findPage(PageDTO<CollectDTO> dto) {
        return collectService.findPage(dto);
    }


    /**
     * 收藏分页查询findById
     * @param id
     * @return
     */
    @ApiOperation("根据id查")
    @PostMapping("/{id}")
    Result<CollectVO> findById(@PathVariable("id") Integer id) {
        return collectService.findById(id);
    }

    /**
     * 根据id删除收藏deleteById
     * @param id
     * @return
     */
    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    Result<CollectVO> deleteById(@PathVariable("id") Integer id) {
        return collectService.deleteById(id);
    }

}

